package com.tuweiya.study.springmvc001.observerPattern;

import com.tuweiya.study.springmvc001.observerPattern.observer.impl.ObserverImpl;
import com.tuweiya.study.springmvc001.observerPattern.observer.impl.ObserverImpl1;
import com.tuweiya.study.springmvc001.observerPattern.observer.impl.ObserverImpl2;
import com.tuweiya.study.springmvc001.observerPattern.observer.impl.ObserverImpl3;
import com.tuweiya.study.springmvc001.observerPattern.subject.impl.AngelbabySubject;

/**
 * @Author: Mr_tu
 * @Date: Create in 13:50 2018/6/7
 * @Description: 观察者模式的测试
 */
public class ObserverMain {

    public static void main(String[] args){

        // 生成观察者
        ObserverImpl observer = new ObserverImpl("王大锤");
        ObserverImpl1 observer1 = new ObserverImpl1("黄晓明");
        ObserverImpl2 observer2 = new ObserverImpl2("郑凯");
        ObserverImpl3 observer3 = new ObserverImpl3("邓超");

        // 定义具体主题
        AngelbabySubject angelbabySubject = new AngelbabySubject();

        // 注册添加观察者
        angelbabySubject.addObservers(observer);
        angelbabySubject.addObservers(observer1);
        angelbabySubject.addObservers(observer2);
        angelbabySubject.addObservers(observer3);

        // 发出通知消息
        angelbabySubject.notifyAllObservers("我不开心");
        // 删除观察者
        angelbabySubject.deleteObservers(observer);
        System.out.println("---------------------");
        angelbabySubject.notifyAllObservers("我不开心");

    }

}
